package cn.weixin.common.util;


import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class XMLUtils {
	//为了效率
	private final static String ROOT_XML = "xml";
	/**
	 * 
	 * @param obj
	 * @param rootName
	 * @return
	 * @throws Exception
	 */
	public static String vo2Xml(Object obj){
		XStream stream = XStreamFactory.getInstance().createXStream(obj.getClass().getName());
		stream.alias(ROOT_XML, obj.getClass());
		String xml = stream.toXML(obj);
		return xml;
	}

	/**
	 * 
	 * @param xml
	 * @param rootName
	 * @param clazz
	 * @return
	 * @throws ClassNotFoundException
	 * @throws Exception
	 */
	public static Object xml2Vo(String xml,Class clazz) {
		XStream stream = XStreamFactory.getInstance().createXStream(clazz.getName());
		stream.alias(ROOT_XML, clazz);
		return stream.fromXML(xml);
	}


}
